using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FernUniHagen.CompilerExtension.DataStructures;
using Roslyn.Compilers.Common;
using Roslyn.Services;

namespace FernUniHagen.CompilerExtension.Adaptor
{
    public class SolutionAdapter
    {
        ISolution _solution;
        IEnumerable<IProject> _projects;
        IProject _currentProject;
       
        


        public ISolution RoslynSolution
        {
            get { return _solution; }
            set { _solution = value; }
        }

        public IEnumerable<IProject> RoslynProjects
        {
            get { return _projects; }
            set { _projects = value; }
        }

        public IProject CurrentProject
        {
            get { return _currentProject; }
            set { _currentProject = value; }
        }

        public CommonCompilation Compilation
        {
            get { return _currentProject.GetCompilation(); }
        }

        public List<SyntaxNodeInfo> GetAnnotatedSyntaxNodes
        {
            get { return AttributeWalker.GetMultiplicityAnnotatedElements(_solution, _currentProject); }
        }

        public ISemanticModel SemanticModel(CommonSyntaxNode node)
        {
            return Compilation.GetSemanticModel(node.SyntaxTree); 
        }

        #region Constructor
        public SolutionAdapter(ISolution solution, IProject project)
        {
            _solution = solution;
            CurrentProject = project;
        }

        public SolutionAdapter(string solution, string project)
        {
            _solution=  Solution.Load(solution);
            CurrentProject = GetProject(project); ;
        }
        #endregion

        public IProject GetProject(string projectName)
        {
            return _solution.Projects.First(p => p.Name.Equals(projectName));
        }

        


    }
}
